package service.Impl;

import dao.mapper.CartMapper;
import org.apache.ibatis.session.SqlSession;
import service.ICartService;
import utils.SqlSessionUtil;
import vo.Book;
import vo.Cart;
import vo.CartLine;

import java.util.List;

public class ICartServiceImpl implements ICartService {
    SqlSession sqlSession=new SqlSessionUtil().sqlSession;
    CartMapper cartMapper=sqlSession.getMapper(CartMapper.class);
    @Override
    public void addCart(int userId) {
        Cart cart=new Cart();
        cart.setUserId(userId);
        cart.setTotalPrice(0);
        cartMapper.addCart(cart);
        sqlSession.commit();
    }

    @Override
    public void changeTotalPrice(int cartId, double totalPrice) {
        cartMapper.changeTotalPrice(cartId,totalPrice);
        sqlSession.commit();
    }


    @Override
    public Cart selectCart(int userId) {
        Cart cart=new Cart();
        cart=cartMapper.selectCart(userId);
        return cart;
    }
}
